/* MASTER */

clear 

clear matrix

set mem 2000m


sysdir set PERSONAL "W:\ado"
set graphics  off

set matsize 2000
global data "D:\ready-made\FLEED_TOTAL\2016\"

global dataCustom "D:\c55\custom-made\"
global dataFolk "D:\ready-made\"

global dataout "W:\workplace\data\"
global results "W:\workplace\results\"
global logfiles "W:\workplace\logs\"


/*=========================

	Create the data 
	

***************************/
cd "W:\workplace\dofiles\"


// Generate data
do step00_cpi  /*run cpi code for price adjustment */
do step01_data_creation_police_workplace /*pull possible crimes from police data */
do step02_create_data_police_workplace_defendant_victim_allyears /*link to fleed data for defendant and victims to identify workplace violence*/
do step03a_defendant_data_creation_police_workplace /*create panel data 5 years before, 5 years after for defendant.*/ 
do step03b_victim_data_creation_police_workplace /*create panel data 5 years before, 5 years after for victims; combine victim with defendant data*/


// do nearest neighborhood matching for defedants and victims
do step04a_defendant_police_workplace_matchedData /*matching using individuals who have not experienced workplace violence as control*/
do step04b_victim_police_workplace_matchedData /*matching using individuals who have not experienced workplace violence as control*/


do step04c_suspect_police_workplace_matchedData_altcounter /*do nearest neighborhood matching using suspects with similar crime types but in non colleague violence as control*/
do step04d_victim_police_workplace_matchedData_altcounter /*do nearest neighborhood matching using victims with similar crime types but in non colleague violence as control*/


// do nearest neighborhood matching for firms, based on firm level characteristics to find the matches 
do step05a_firm_matchedData_violentfirms /* matching is based on firm characteristics 5 years prior to violence and for firms that are exisiting 5 years prior to violence*/
do step05b_firm_matchedData_violentfirms /* matching is for firms that exist less than 5 years prior to violence, only matching using firm characteristics 2 years prior to violence, and combine it with the above data to form the firm matched data*/



// Supplementary codes 
do step06_crime_eachindividual /*crime records data, used for table 1 summary statistics*/
do step07_firm_matchedData_nonworkplace /*do nearest neighborhood matching for firms, using non colleague violence perp's firms as treatment firms*/



/*=========================

Figures and Tables in the QJE paper 
	
=========================*/

/*=========================
// Figures 
=========================*/


do f01_figure_descriptive_earn_growth  /*descriptive earnings growth: Figure 1 in QJE */
do f024_figure_DiD_hetero_fullinteract /*descriptive and regression asymmetry results: Figure 2 and Figure 4 in QJE*/

do f03a_match_causal_victim_draft /*victim event study: Figure 3 in QJE*/
do f03b_match_causal_defendant_draft /*defendant event study: Figure 3 in QJE*/

do f05_match_causal_perp_victim_altcounter /*DiD coefplot for using non colleague violence as counterfactual: Figure 5 in QJE*/ 
do f06_power_victim_perp_desc /*Descriptive power, showing female victims more likely to be attacked by powerful perps: Figure 6 in QJE*/

do f07_match_causal_firm /*firm event study: share of female, Figure 7 in QJE*/
do f08_figure_DiD_firm_outcomes_decomposition /*firm results decomposition: share of female, turnover, newfire, Figure 8 in QJE*/
do f09_match_causal_nonworkplace_firm_share_female /*firm event study: non colleague violence on share of female Figure 9 in QJE*/
do f10_manager_heterogeneity_firm_share_female /*firm heterogeneous results by female manager, Figure 10 in QJE*/


/*=========================
// Tables 
=========================*/
do t123_table_descriptive /*descriptive tables: table 1, 2 and 3 in QJE*/
do t4a_table_DiD_perp_hetero /*DiD regression table: defendants power dynamics and female manager: table 4 in QJE*/
do t4b_table_DiD_victim_hetero /*DiD regression table: victim power dynamics and female manager: table 4 in QJE*/


do t05a_table_DiD_perp_hetero_fullinteract /*DiD regression table: pull mm mf together and do full interaction heterogeneity, table 5 in QJE*/
do t05b_table_DiD_victim_hetero_fullinteract /*DiD regression table: pull mm mf together and do full interaction heterogeneity, table 5 in QJE*/


do t6a_table_DiD_perp_manager_hetero /*DiD regression table: defendants female manager: table 6 in QJE*/
do t6b_table_DiD_victim_manager_hetero /*DiD regression table: victim female manager: table 6 in QJE*/
do t7_table_DiD_firm_topwomen_hetero /*DiD regression table: firm heterogeneity results: table 7 in QJE*/


